package com.mjlf.test_shiro.controller;

import com.mjlf.test_shiro.entity.Person;
import com.mjlf.test_shiro.service.LoginService;
import com.mjlf.test_shiro.service.PermissionService;
import com.mjlf.test_shiro.service.PersonService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import javax.validation.Valid;

/**
 * @ClassName: PersonContoller
 * @Author: majun
 * @CreateDate: 2018/10/17 17:05
 * @Version: 1.0
 * @Description: TODO
 */

@RestController
@RequestMapping("/test_shiro")
@EnableSwagger2
public class PersonContoller {
    @Autowired
    private LoginService loginService;
    @Autowired
    private PersonService personService;
    @Autowired
    private PermissionService permissionService;

    /**
     * 添加用户
     * @param person
     * @return
     */
    @ApiOperation(value = "添加用户",notes = "添加用户")
    @ApiResponses({
            @ApiResponse(code = 200, message = "I don't know what message")
    })
    @RequestMapping(path = "/add", method = RequestMethod.POST)
    @RequiresPermissions("write")
    public String add(@Valid @RequestBody Person person){
        System.out.println();
        personService.addPerson(person);
        return "成功";
    }

    /**
     * 查询用户
     * @return
     */
    @ApiOperation(value = "添加用户",notes = "添加用户")
    @ApiResponses({
            @ApiResponse(code = 200, message = "I don't know what message")
    })
    @RequestMapping(path = "/get", method = RequestMethod.GET)
    @RequiresPermissions("read")
    public String get(){
        personService.queryPerson();
        return "成功";
    }

    /**
     * 查询用户
     * @return
     */
    @ApiOperation(value = "添加用户",notes = "添加用户")
    @ApiResponses({
            @ApiResponse(code = 200, message = "I don't know what message")
    })
    @RequestMapping(path = "/delete", method = RequestMethod.GET)
    @RequiresPermissions("write")
    public String delete(){
        personService.queryPerson();
        return "成功";
    }

    /**
     * 查询用户
     * @return
     */
    @ApiOperation(value = "添加用户",notes = "添加用户")
    @ApiResponses({
            @ApiResponse(code = 200, message = "I don't know what message")
    })
    @RequestMapping(path = "/other", method = RequestMethod.GET)
    @RequiresPermissions("other")
    public String other(){
        personService.queryPerson();
        return "成功";
    }
}
